package com.demo.controller;

import com.demo.entity.ProductRecord;

import com.demo.repository.ProductRecordRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.Map;

/**
 * @author lepdou 2017-06-18
 */
@RequestMapping(value = "/admin/sales")
@RestController
public class SaleController {

  @Autowired
  private ProductRecordRepo productRecordRepo;

  @RequestMapping(value = "", method = RequestMethod.GET)
  public Iterator<ProductRecord> getSaleList(){
    Iterator<ProductRecord> records = productRecordRepo.findAll().iterator();
    return records;
  }

  @RequestMapping(value = "/groupByUser", method = RequestMethod.GET)
  public Iterator<Map<String, Object>> getSaleListGroupByUser(){
      Iterator<Map<String, Object>> records = productRecordRepo.getGroupByUserIdOrderBySumMoney().iterator();
      return records;
  }
  @RequestMapping(value = "/groupByProduct", method = RequestMethod.GET)
  public Iterator<Map<String, Object>> getSaleListGroupByProduct(){
      Iterator<Map<String, Object>> records = productRecordRepo.getGroupByProductIdOrderBySumMoney().iterator();
      return records;
  }
}
